package com.lam.mall.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lam.common.base.controller.BaseController;
import com.lam.common.base.domain.Result;
import com.lam.common.components.dict.DictUtil;
import com.lam.common.components.dict.annotation.DictAutoTransfer;
import com.lam.common.components.dict.model.DictFeature;
import com.lam.common.context.TokenUtils;
import com.lam.common.validate.group.Update;
import com.lam.framework.annotation.ParamInject;
import com.lam.framework.operLog.annotation.Log;
import com.lam.framework.operLog.enums.BusinessType;
import com.lam.mall.entity.OrderAddr;
import com.lam.mall.param.OrderAddrParam;
import com.lam.mall.service.OrderAddrService;

/**
 * 订单配送地址Controller
 * 
 * @author admin
 * @date 2023-04-25
 */
@Log(title = "订单配送地址")
@ParamInject
@RestController
@RequestMapping("/${adminPath}/mall/orderAddr")
public class OrderAddrController extends BaseController {

    @Autowired
    private OrderAddrService orderAddrService;

    /**
     * 查询订单配送地址列表
     */
    @Log(oper="分页查询")
    @PreAuthorize("@ss.hasPm('mall:orderAddr:list')")
    @GetMapping("/list")
    public Result list(OrderAddrParam param) {
    
        startPage();
        List<OrderAddr> list = orderAddrService.selectList(param);
        return Result.ok(getTableData(list));
    }

    /**
     * 获取订单配送地址详细信息
     */
    @DictAutoTransfer
    @Log(oper="根据ID查询")
    @PreAuthorize("@ss.hasPm('mall:orderAddr:query')")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable("id") String id) {
    
        return Result.ok(orderAddrService.selectById(id));
    }

    /**
     * 修改订单配送地址
     */
    @PreAuthorize("@ss.hasPm('mall:orderAddr:edit')")
    @Log(businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@Validated(Update.class) @RequestBody OrderAddr orderAddr) {
    
    	orderAddr.setUpdateBy(TokenUtils.getLoginUsername());
    	orderAddr.setUpdateTime(new Date());
    	
    	DictUtil.convertJavaObject(orderAddr, DictFeature.create().transfer2Json(false));
    	orderAddrService.update(orderAddr);
        return Result.ok(orderAddr);
    }

}
